<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2019-11-27
 * Time: 11:03
 * 小程序用户表
 */

namespace app\api\model;


class User extends BaseModel
{
    protected $hidden = ['openid','update_time','delete_time'];

    public static function getOpenId($openid)
    {
        $user = self::where('openid','=',$openid)
            ->find();
        return $user;
    }

    // 关联会员信息
    public function member()
    {
        return $this->belongsTo('Member','id','user_id');
    }

    public function getMemberStartTimeAttr($value,$data)
    {
        $time = time();
        if(!$value) {
            return '';
        } else {
            if($time > $data['member_end_time']) {
                return '';
            } else {
                return date('Y/m/d',$value);
            }
        }
    }

    public function getMemberEndTimeAttr($value)
    {
        $time = time();
        if(!$value) {
            return '会员福利多';
        } else {
            if($time > $value) {
                return '会员已过期';
            } else {
                return date('Y/m/d',$value);
            }
        }
    }
}